//
//  ZGSmoreSpecialViewController.m
//  Tour
//
//  Created by dllo on 15/10/23.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "ZGSmoreSpecialViewController.h"
#import "AdvanceEdit.h"
#import "ZGSmoreSperciaView.h"
#import "ZGSMoreSpeciaCell.h"
#import "ScrollWebViewController.h"
@interface ZGSmoreSpecialViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain)UITableView *tableView;
@property (nonatomic, retain)NSMutableArray *arr;
@end

@implementation ZGSmoreSpecialViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 64)];
    [self.view addSubview:headView];
//    headView.layer.borderWidth = 0.5;
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(0, 32, 80, 32);
    headView.backgroundColor = [UIColor whiteColor];
//    button.layer.borderWidth = 1;
    [button setTitle:@"返回" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    [headView addSubview:button];
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.rowHeight = 300;
    [self.tableView registerClass:[ZGSMoreSpeciaCell class] forCellReuseIdentifier:@"reuse"];
    [self.view addSubview:self.tableView];
    [self creatData];
}
- (void)creatData{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:@"http://open.qyer.com/qyer/special/topic/special_list?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&lat=38.88265791889842&lon=121.5393354953514&page=1&track_app_channel=App%2520Store&track_app_version=6.7&track_device_info=iPhone7%2C1&track_deviceid=CD8DD9AA-C227-45CD-A07E-DA485B537E39&track_os=ios%25208.4.1&v=1" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSMutableDictionary *dic = responseObject;
        NSArray *array = [ZGSmoreSperciaView baseModelArr:dic[@"data"]];
        self.arr = [NSMutableArray array];
        for (ZGSmoreSperciaView *spercia in array) {
            [self.arr addObject:spercia];
        }
        [self.tableView reloadData];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        
    }];
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ZGSMoreSpeciaCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];
    [cell.BigImage sd_setImageWithURL:[NSURL URLWithString:[self.arr[indexPath.row] photo]]placeholderImage:[UIImage imageNamed:@"10.jpeg"]];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ScrollWebViewController *webVC = [[ScrollWebViewController alloc] init];
    ZGSmoreSperciaView *more = [[ZGSmoreSperciaView alloc] init];
    more = self.arr[indexPath.row];
    webVC.urlStr = more.url;
//    [self.navigationController pushViewController:webVC animated:YES];
    [self presentViewController:webVC animated:YES completion:^{
        
        
    }];
}
- (void)click:(UIButton *)button{
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
